<!-- 试题重复框 -->
<template>
  <el-dialog
    v-loading="loading"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    title="试题重复"
    :visible="open"
    width="700px"
    append-to-body
    @close="cancel()"
    custom-class="custom-dialog-1"
  >
    <div class="all_content">
      <div class="tip">检测到文档中包含以下重复试题</div>
      <el-table
        :header-cell-style="tableHeaderStyle"
        :data="arr"
        class="cum_table"
      >
        <el-table-column
          label="序号"
          width="50"
          type="index"
          align="center"
        ></el-table-column>

        <el-table-column label="题型" align="center" width="100">
          <template slot-scope="scope">
            {{ scope.row.topicType }}
          </template>
        </el-table-column>
        <el-table-column label="题干" align="left">
          <template slot-scope="scope">
            {{ scope.row.question }}
          </template>
        </el-table-column>
        <el-table-column label="重复次数" width="100" align="center">
          <template slot-scope="scope">
            <div style="color: #e95756">
              {{ scope.row.count }}
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div slot="footer" class="dialog1-dialog-footer">
      <div v-preventReClick @click="cancel" class="cancel_btn">取消导入</div>
      <!-- 导入方式 1-全部导入 2-覆盖重复试题 -->
      <div
        v-preventReClick
        type="primary"
        class="confirm1_btn"
        @click="repeatImport(2)"
      >
        去重导入
      </div>
      <div
        v-preventReClick
        type="primary"
        class="confirm2_btn"
        @click="repeatImport(1)"
      >
        重复导入
      </div>
    </div>
  </el-dialog>
</template>

<script>
import { importDataimport } from '@/api/questions/index.js'

export default {
  props: {
    open: Boolean,
    arr: Array,
    // 用于导入的数组
    data: Array,
    indexId: [String, Number]
  },
  data() {
    return {
      loading: false,
      repeats: [
        { type: '选择题', num: 0, color: '#6796FF' },
        { type: '多选题', num: 0, color: '#F36E63' },
        { type: '判断题', num: 0, color: '#6BCF86' },
        { type: '填空题', num: 0, color: '#F9C155' },
        { type: '简答题', num: 0, color: '#53D2C6' },
        { type: '操作题', num: 0, color: '#A967FF' }
      ],
      importSuccessOpen: false,
      tableHeaderStyle: {
        'background-color': '#f8f8f9',
        color: '#333333',
        'font-size': '14px',
        'font-family': 'PingFangSC, PingFang SC',
        'font-weight': '400'
      }
    }
  },
  watch: {
    open(e) {
      if (e) {
      }
    }
  },
  methods: {
    async repeatImport(e) {
      console.log(this.indexId, e, this.data)
      try {
        this.loading = true
        let res = await importDataimport(this.indexId, e, this.data)
        if (res.code == 200) {
          // 导入成功
          this.$modal.msgSuccess('导入成功！')
          this.$emit('update:open', false)
          this.$emit('importSuccess', res.data)
        }
      } finally {
        this.loading = false
      }
    },
    back() {
      this.importSuccessOpen = false
      this.cancel()
    },
    // 取消按钮
    cancel() {
      this.$emit('update:open', false)
    }
  },
  created() {
  },
  mounted() {
  }
}
</script>
<style scoped lang="scss">
::v-deep .el-dialog .el-dialog__header {
  padding: 20px 40px 10px 24px !important;
}

::v-deep .custom-dialog-1 .el-dialog__footer {
  border-top: 1px solid rgba(0, 0, 0, 0.09);
  padding: 0 24px !important;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

::v-deep .custom-dialog-1 .el-dialog__footer .dialog1-dialog-footer {
  display: flex;
}

::v-deep .custom-dialog-1 .el-dialog__footer .dialog2-dialog-footer {
  display: flex;
}

::v-deep .custom-dialog-1 .el-dialog__body {
  padding: 16px 24px 0 24px !important;
}

@mixin btn_plain($bg_color, $color) {
  background: $bg_color;
  color: $color;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  user-select: none;

  &:active,
  &:hover {
    background: darken($bg_color, 5%);
    color: darken($color, 18%);
  }

  &:disabled {
    background: lighten($bg_color, 5%);
    color: lighten($color, 40%);
  }

  @content;
}

@import "../../../assets/styles/mixin.scss";
.cancel_btn {
  @include btn_plain(#ffffff, #666666) {
    margin: 0 0 0 0;
    width: 88px;
    text-align: center;
    height: 32px;
    line-height: 32px;
    box-sizing: border-box;
    border-radius: 8px;
    border: 1px solid #edeff0;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC, sans-serif;
    font-weight: 400;
  }
}

.confirm1_btn {
  @include plain_hover(rgba(40, 178, 139, 0.2), #28b28b, #ffffff) {
    width: 80px;
    height: 32px;
    line-height: 32px;
    border-radius: 8px;
    border: 1px solid #28b28b;
    font-family: PingFangSC, PingFang SC, sans-serif;
    font-weight: 400;
    font-size: 14px;
    font-style: normal;
    margin-left: 16px;
  }

  .btn_icon {
    color: #28b28b;
    width: 16px;
    height: 16px;
    margin-right: 4px;
  }

  &:hover {
    .btn_icon {
      color: #ffffff;
    }
  }

  &:active {
    .btn_icon {
      color: #ffffff;
    }
  }
}

.confirm2_btn {
  @include btn_plain(#28b28b, #ffffff) {
    margin: 0 0 0 16px;
    width: 88px;
    text-align: center;
    height: 32px;
    line-height: 32px;
    box-sizing: border-box;
    border-radius: 8px;
    border: 1px solid #edeff0;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC, sans-serif;
    font-weight: 400;
  }
}

.cum_table {
  margin-bottom: 16px;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  border: 1px solid #e8eaeb;
}

::v-deep .el-table:before {
  height: 0;
}

.tip {
  font-family: PingFangSC, PingFang SC, sans-serif;
  font-weight: 400;
  font-size: 14px;
  color: #e95756;
  line-height: 20px;
  text-align: left;
  font-style: normal;
  margin-bottom: 16px;
}
</style>
